package com.shop.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Date;

@Component
public class MyLogGateWayFilter implements GlobalFilter, Ordered {


    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
   //     System.out.println("***********come in 全局过滤器"+new Date());
    //   String name= exchange.getRequest().getQueryParams().getFirst("uname");
     //   if(name==null){
        //    System.out.println("***********非法用户*************"+new Date());
         //   exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE);
           // return exchange.getResponse().setComplete();
      //  }
        return chain.filter(exchange);
    }
//加载顺序，越小就优先级越高
    public int getOrder() {
        return 1;
    }
}
